package com.shop.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shop.bean.Products;
import com.shop.dao.ProductsDAO;
import com.shop.factory.ProductsDAOFactory;

public class AddProductServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//接收表单信息
		String name = request.getParameter("name");
		String price = request.getParameter("price");
		String agio = request.getParameter("agio");
		//将商品信息设置到对象中
		Products p = new Products();
		p.setName(name);
		p.setPrice(Double.parseDouble(price));
		p.setAgio(Double.parseDouble(agio));
		//
		ProductsDAO pd = ProductsDAOFactory.createProductsDAOImpl();
		pd.addProduct(p);
		request.getRequestDispatcher("AddSuccess.html").forward(request, response);
	}

}
